home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 376-400 / disk_386 / xlispstat / src2.lzh / XLisp-Stat / statfloat.c < prev    next >
C/C++ Source or Header  |  1990-10-02  |  2KB  |  134 lines

  1. /* statfloat - Floating point operations with error checking           */
  2. /* XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney                  */
  3. /* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz    */
  4. /* You may give out copies of this software; for conditions see the    */
  5. /* file COPYING included with this distribution.                       */
  6.  
  7. #include "xlisp.h"
  8. #include "osdef.h"
  9. #ifdef ANSI
  10. #include "xlsproto.h"
  11. #else
  12. #include "xlsfun.h"
  13. #endif ANSI
  14.  
  15. # ifdef MACINTOSH
  16. extern long flog(), fexp(), fsqrt(), ftimes(), fdivid(), fexpt();
  17. # endif
  18.  
  19. double f_plus(x, y)
  20.      double x, y;
  21. {
  22.   return(x + y);
  23. }
  24.  
  25. double f_minus(x, y)
  26.      double x, y;
  27. {
  28.   return(x - y);
  29. }
  30.  
  31. double f_times(x, y)
  32.      double x, y;
  33. {
  34. # ifdef DODO /* MACINTOSH */
  35.   short double sa, sx, sy;
  36.   double a;
  37.  
  38.   sx = x;
  39.   sy = y;
  40.   f77sub(ftimes, &sa, &sx, &sy);
  41.   a = sa;
  42.   return(a);
  43. # else
  44.   return(x * y);
  45. # endif DODO
  46. }
  47.  
  48. double f_divide(x, y)
  49.      double x, y;
  50. {
  51. #ifdef DODO /* MACINTOSH */
  52.   short double sa, sx, sy;
  53.   double a;
  54.  
  55.   if (y == 0.0) xlfail("division by zero");
  56.  
  57.   sx = x;
  58.   sy = y;
  59.   f77sub(fdivid, &sa, &sx, &sy);
  60.   a = sa;
  61.   return(a);
  62. #else
  63.   return(x / y);
  64. #endif DODO
  65. }
  66.  
  67. double f_log(x)
  68.      double x;
  69. {
  70. # ifdef DODO /* MACINTOSH */
  71.   short double sa, sx;
  72.   double a;
  73.     
  74.   if (x <= 0) xlfail("logarithm of nonpositive number");
  75.   sx = x;
  76.   f77sub(flog, &sa, &sx);
  77.   a = sa;
  78.   return(a);
  79. # else
  80.   return(log(x));
  81. # endif DODO
  82. }
  83.  
  84. double f_exp(x)
  85.      double x;
  86. {
  87. # ifdef DODO /* MACINTOSH */
  88.   short double sa, sx;
  89.   double a;
  90.     
  91.   sx = x;
  92.   f77sub(fexp, &sa, &sx);
  93.   a = sa;
  94.   return(a);
  95. # else
  96.   return(exp(x));
  97. # endif DODO
  98. }
  99.  
  100. double f_sqrt(x)
  101.      double x;
  102. {
  103. # ifdef DODO /* MACINTOSH */
  104.   short double sa, sx;
  105.   double a;
  106.  
  107.   if (x < 0) xlfail("square root of negative number");
  108.   sx = x;
  109.   f77sub(fsqrt, &sa, &sx);
  110.   a = sa;
  111.   return(a);
  112. # else
  113.   return(sqrt(x));
  114. # endif DODO
  115. }
  116.  
  117. double f_expt(x, y)
  118.      double x, y;
  119. {
  120. # ifdef DODO /* MACINTOSH */
  121.   short double sa, sx, sy;
  122.   double a;
  123.  
  124.   sx = x;
  125.   sy = y;
  126.   f77sub(fexpt, &sa, &sx, &sy);
  127.   a = sa;
  128.   return(a);
  129. # else
  130.   return(pow(x, y));
  131. #endif DODO
  132. }
  133.  
  134.